package com.gome.boot.config.elasticsearch.search;

import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.domain.Pageable;

/**
 * Elasticsearch查询条件对象.
 *
 * @author baoxiufeng
 */
public class SearchCondition {

    /**
     * 查询条件构建对象.
     */
    private QueryBuilder queryBuilder;

    /**
     * 查询分页信息对象
     */
    private Pageable pageable;

    /**
     * 索引名称
     */
    private String index;

    /**
     * 索引数据类型
     */
    private String type;

    /**
     * 查询Shard路由
     */
    private String routing;

    /**
     * 查询Doc标识
     */
    private String id;
    /**
     * 多集群HASH模式选择器KEY.
     * <br/>仅用于多集群模式.
     * <br/>多集群使用HASH模式选择器时默认使用routing值.
     */
    private Object hashKey;

    /**
     * 默认构造方法.
     */
    public SearchCondition() {
    }

    /**
     * 构造方法.
     *
     * @param queryBuilder 查询条件构建对象
     */
    public SearchCondition(QueryBuilder queryBuilder) {
        this.queryBuilder = queryBuilder;
    }


    /**
     * 构造方法.
     *
     * @param queryBuilder 查询条件构建对象
     * @param pageable 查询分页信息对象
     */
    public SearchCondition(QueryBuilder queryBuilder, Pageable pageable) {
        this.queryBuilder = queryBuilder;
        this.pageable = pageable;
    }

    /**
     * 构造方法.
     *
     * @param queryBuilder 查询条件构建对象
     * @param pageable 查询分页信息对象
     * @param routing 查询Shard路由
     */
    public SearchCondition(QueryBuilder queryBuilder, Pageable pageable, String routing) {
        this.queryBuilder = queryBuilder;
        this.pageable = pageable;
        this.routing = routing;
    }

    public QueryBuilder getQueryBuilder() {
        return queryBuilder;
    }

    public void setQueryBuilder(QueryBuilder queryBuilder) {
        this.queryBuilder = queryBuilder;
    }

    public Pageable getPageable() {
        return pageable;
    }

    public void setPageable(Pageable pageable) {
        this.pageable = pageable;
    }

    public String getIndex() {
        return index;
    }

    public void setIndex(String index) {
        this.index = index;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getRouting() {
        return routing;
    }

    public void setRouting(String routing) {
        this.routing = routing;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Object getHashKey() {
        return hashKey == null ? routing : hashKey;
    }

    public void setHashKey(Object hashKey) {
        this.hashKey = hashKey;
    }
}
